package com.qf.xml.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.Arrays;

public class CacheAdvice {

    public void before(JoinPoint jp){
        //JoinPoint中封装了目标方法的参数
        Object[] args = jp.getArgs();
        System.out.println("目标方法的参数:" + Arrays.toString(args));

        System.out.println("查询缓存~~");
    }

    public void around(ProceedingJoinPoint pjp)  {
        //ProceedingJoinPoint这个对象中封装了目标方法
        Object[] args = pjp.getArgs();
        System.out.println("目标方法的参数:" + Arrays.toString(args));

        args[0] = 20;
        try {
            System.out.println("前置");

            //执行目标方法
            Object proceed = pjp.proceed(args);

            System.out.println("返回后");
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("异常后");
        }finally {
            System.out.println("最终");
        }
    }
}
